using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

namespace Login.Server
{
    public class SingleButtonSelector : MonoBehaviour
    {
        public Button[] buttons;
        private Button currentlySelectedButton;

        private void Start()
        {
            // 为每个按钮添加点击事件监听器
            foreach (var button in buttons) button.onClick.AddListener(() => SelectButton(button));
        }

        private void SelectButton(Button button)
        {
            // 取消当前选中按钮的选中状态
            if (currentlySelectedButton != null) EventSystem.current.SetSelectedGameObject(null);

            // 设置新的选中按钮
            currentlySelectedButton = button;
            EventSystem.current.SetSelectedGameObject(button.gameObject);
        }
    }
}